from utils import MetaBadge as Badge

##  Models  ##
"""
YOU NEED TO DELETE THESE AND IMPORT YOUR OWN BEFORE THIS APP WILL WORK
"""
from basic_profiles.models import Profile
from voting.models import Vote
from forum.models import Thread, Post

# # # # # #  Profile Badges  # # # # # # 

class autobiographer(Badge):
    model = Profile
    one_time_only = True
    badge_info = {
        "db_name" : "autobiographer",
        "title" : "Autobiographer",
        "description" : "Completed all user profile fields",
        "level" : "b",          
        }
    conditions = (
        "instance.name",
        "instance.about",
        "instance.location",
        )

        
# # # # # #  Voting Badges  # # # # # #

class supporter(Badge):
    model = Vote
    one_time_only = True
    badge_info = {
        "db_name" : "supporter",
        "title" : "Supporter",
        "description" : "First up vote",
        "level" : "b",                                         
        }
    conditions = (
        # Must be a downvote
        "instance.vote == 1",
        )
    
class critic(Badge):
    model = Vote
    one_time_only = True
    badge_info = {
        "db_name" : "critic",
        "title" : "Critic",
        "description" : "First down vote",
        "level" : "b",                                         
        }
    conditions = (
        # Must be a downvote
        "instance.vote == -1",
        )

class civic_duty(Badge):
    model = Vote
    one_time_only = True
    badge_info = {
        "db_name" : "civic_duty",
        "title" : "Civic Duty",
        "description" : "Voted 300 times",
        "level" : "s",                                         
        }
    conditions = (
        "instance.user.vote_set.count() > 300", 
        )



# # # # # #  Post Badges  # # # # # #

# by number of responses

class nice_post(Badge):
    model = Post
    user_field_name = "instance.thread.first_post.author"
    badge_info = {
        "db_name" : "nice_post",
        "title" : "Nice Post",
        "description" : "Post got 10 responses",
        "level" : "b",                                         
        }
    conditions = (
        # not counting posts made by the original author
        "instance.thread.post_set.exclude(author=instance.thread.first_post.author).count() >= 10",
        )

class great_post(Badge):
    model = Post
    user_field_name = "instance.thread.first_post.author"
    badge_info = {
        "db_name" : "great_post",
        "title" : "Great Post",
        "description" : "Post got 25 responses",
        "level" : "s",                                         
        }
    conditions = (
        # not counting posts made by the original author
        "instance.thread.post_set.exclude(author=instance.thread.first_post.author).count() >= 25", 
        )

class otaku_post(Badge):
    model = Post
    user_field_name = "instance.thread.first_post.author"
    badge_info = {
        "db_name" : "otaku_post",
        "title" : "Otaku Post",
        "description" : "Post got 100 responses",
        "level" : "g",                                         
        }
    conditions = (
        # not counting posts made by the original author
        "instance.thread.post_set.exclude( author=instance.thread.first_post.author ).count() >= 100",
        )

# by number of views...

class interesting_post(Badge):
    model = Thread
    user_field_name = "instance.first_post.author"
    badge_info = {
        "db_name" : "interesting_post",
        "title" : "Interesting Post",
        "description" : "Post viewed 1,000 times",
        "level" : "b",                                         
        }
    conditions = (
        "instance.views >= 1000", 
        )
    
class popular_post(Badge):
    model = Thread
    user_field_name = "instance.first_post.author"
    badge_info = {
        "db_name" : "popular_post",
        "title" : "Popular Post",
        "description" : "Post viewed 2,500 times",
        "level" : "s",                                         
        }
    conditions = (
        "instance.views >= 2500", 
        )

class famous_post(Badge):
    model = Thread
    user_field_name = "instance.first_post.author"
    badge_info = {
        "db_name" : "famous_post",
        "title" : "Famous Post",
        "description" : "Post viewed 10,000 times",
        "level" : "g",                                         
        }
    conditions = (
        "instance.views >= 10000", 
        )
    

# # # # # #  Response Badges  # # # # # #

# by number of votes...

class nice_response(Badge):
    model = Vote
    badge_info = {
        "db_name" : "nice_response",
        "title" : "Nice Response",
        "description" : "Response voted up 10 times",
        "level" : "b",                                         
        }
    conditions = (
        "instance.object.score >= 10", 
        )

class great_response(Badge):
    model = Vote
    badge_info = {
        "db_name" : "great_response",
        "title" : "Great Response",
        "description" : "Response voted up 25 times",
        "level" : "s",                                         
        }
    conditions = (
        "instance.object.score >= 25", 
        )

class otaku_response(Badge):
    model = Vote
    badge_info = {
        "db_name" : "otaku_response",
        "title" : "Otaku Response",
        "description" : "Response voted up 100 times",
        "level" : "g",                                         
        }
    conditions = (
        "instance.object.score >= 100", 
        )
